import os

from django.test import TestCase

#要单独运行文件就需要这一步，可以在manage.py文件中复制
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "Django_01.settings")
# Create your tests here.
from rest_framework import serializers


class User(object):
    def __init__(self,username,age):
        self.username = username
        self.age = age
        self.count = 3

class UserSerializer(serializers.Serializer):
    """序列化器类"""
    #序列化器字段 = serializers.字段类型（选项参数）
    username = serializers.CharField()
    age = serializers.IntegerField()
    count = serializers.IntegerField()

#创建一个用户实例模型对象
user = User('sb', 18)
#创建一个序列化器实例对象，把用户实例传入
serializer = UserSerializer(user)
#获取序列化之后的字典数据
print(serializer.data)
